{extend name="$BASE_LIST" /}
{block name="body"}
<link rel="stylesheet" type="text/css" href="__STATIC__/monthPicker/dateRange.css"/>
<link rel="stylesheet" type="text/css" href="__STATIC__/monthPicker/monthPicker.css"/>
<div class="right-main">
    <div class="page_nav" id="js_page_nav"><span class="page_title">{$page_nav}</span></div>
    <div id="js_main_header" class="ui-form main_header">
        <div class="left margin-right-5">
            <input style="width:200px" class="form-control" id="month_picker" size="20"/>
        </div>
        <!-- <span>
            <select name="is_frozen" id="is_frozen" class="form-control" style="width:120px">
                <option value="">筛选用户状态</option>
                <option value="0">正常</option>
                <option value="1">冻结</option>
            </select>
        </span>
 -->        
        <span class="right">
            <button type="button" id="js_addBtn" class="btn btn-primary"><i class="icon wb-plus"></i> 添加演员</button>
        </span>
        <span class="frm_input_box search append">
            <a href="javascript:void(0);" id="js_search" class="frm_input_append">
                <i class="icon wb-search" title="搜索"></i>
            </a>
            <input type="text" id="js_keyword" placeholder="请输入用户名或手机号" value="" class="frm_input"/>
        </span>
    </div>
    <table id="grid-table">
        <thead frozen="true">
        <th data-options="field:'head_img',width:100,align:'center',formatter:formatImg">演员头像</th>
        <th data-options="field:'id',width:80,align:'center'">用户ID</th>
        <th data-options="field:'username',width:140,align:'center'">演员名称</th>
        <th data-options="field:'phone',width:140,align:'center'">手机号</th>
        </thead>
        <thead>
        <tr>
            <th data-options="field:'intro',width:140,align:'center'">简介</th>
            <th data-options="field:'class_name',width:140,align:'center'">分类</th>
            <th data-options="field:'register_time',width:150, align:'center'">注册时间</th>
            <th data-options="field:'_oper',halign:'center',formatter: formatOper">操作</th>
        </tr>
        </thead>
    </table>
</div>
{/block}
{block name="script"}
<script type="text/javascript" src="__STATIC__/monthPicker/dateRange.js"></script>
<script type="text/javascript" src="__STATIC__/monthPicker/monthPicker.js"></script>
<script type="text/javascript">

    var myDate = new Date();
    var month = parseInt(myDate.getMonth()) + 1;
    var toDay = myDate.getFullYear() + '-' + month + '-' + myDate.getDate();
    var dateRange = new pickerDateRange('month_picker', {
        startDate: '2000-01-01',
        endDate: toDay,
        defaultText: ' 至 ',
        theme: 'ta'
    });

    $("#js_addBtn").click(function () {
        if ($(this).hasClass("disabled")) {
            return;
        }
        var url = getURL('actor_set');
        openBarWin('添加用户',1000, 500, url, function () {
            reload();
        });
    });


    function formatOper(value, row, index) {
        var html = '<span class="grid-operation">';
        html += '<button type="button" onclick="edit(' + row['id'] + ')" class="btn btn-xs btn-default edit-btn"><i class="icon wb-edit"></i>编辑资料</button>';
        html += '<button type="button" onclick="del(' + row['id'] + ')" class="btn btn-xs btn-default del-btn"><i class="icon wb-close"></i>删除</button>';
        html += '</span>';
        return html;
    }
    function formatStatus(value, row, index) {
        var text = '<span style="color:red">正常</span>';
        if (value == '1')
            text = '<span style="color:green">冻结</span>';
        return text;
    }

    function formatImg(value) {
        if (value) {
            var html = '<div class="img_box" ><img style="height:35px; margin:5px" src="' + value + '" class="img" /></div>';
        } 
        return html;
    }
    $('body').on('click','.img',function(){
        src = $(this).attr('src');
        layer.open({
            type: 1,
            area: ['60%', '60%'],
            maxmin: false,
            content: '<div style="background:#000;width:100%;height:700px;display: table-cell;text-align: center;vertical-align: middle;"><img style="display: block;margin: auto;max-width: 98%;max-height: 98%;" src="'+src+'"></div>',
        });
    })


    $(function () {
        $('#grid-table').datagrid({
            url: getURL('loadList'),
            method: "GET",
            height: getGridHeight(),
            rownumbers: true,
            singleSelect: true,
            remoteSort: false,
            multiSort: true,
            emptyMsg: '<span>无相关数据</span>',
            pagination: true,
            pageSize: 20,
            showFooter:true,
            onLoadSuccess: function(data){
                $('#grid-table').datagrid('reloadFooter', [
                    // {
                    //     username: 'USDT积分统计',
                    //     amount: data.total_usdt
                    // },
                    // {
                    //     username: '元气豆积分统计',
                    //     amount: data.total_bean
                    // },
                    // {
                    //     username: '冻结资产积分统计',
                    //     amount: data.total_freeze
                    // }
                ]);
            }
        });
        //设置分页控件
        $('#grid-table').datagrid('getPager').pagination({
            pageSize: 20, //每页显示的记录条数，默认为10
            pageList: [20, 30, 50]
        });
    });


    function edit(id) {
        var url = getURL('edit', 'id=' + id);
        openBarWin('编辑', 1000, 700, url, function () {
            reload();
        }, ['确定', '取消']);
    }

    function del(id) {
        confirm("删除后会员数据无法找回。确认要删除此会员吗？", function () {
            var url = getURL('del');
            $.getJSON(url, {id: id}, function (json) {
                if (json.success)
                    reload();
                else
                    alert(json.message);
            });
        });
    }

    $("#js_search").click(function () {
        reload();
    });

    $("#js_expBtn").click(function () {
        location.href = getURL('export');
    });
    $("#is_frozen").change(function () {
        reload();
    });
    $("#is_auth").change(function () {
        reload();
    });
    $("#user_order").change(function () {
        reload();
    });

    function reload() {
        var keyword = $("#js_keyword").val();
        var is_frozen = $("#is_frozen").val();
        var month_picker = $("#month_picker").val();
        var arr = month_picker.split(" 至 ");
        var startDate = arr[0];
        var endDate = arr[1];
        $('#grid-table').datagrid('reload', {
            keyword: keyword,
            is_frozen: is_frozen,
            startDate: startDate,
            endDate: endDate
        });
    }


</script>
{/block}